<template>
	<view class="">
		<u-navbar back-text="返回" title="热门推荐"></u-navbar>
		<!-- 数据列表 -->
		<mescroll-uni :top="top" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :up="upOption">
			<view class="u-p-30">
				<detail-card class="u-m-b-30" v-for="item in hotList" :key="item.book_id" :bookId="item.book_id" :name="item.name"
				 :image="item.image" :writer="item.writer" :is_over="item.is_over" :intro="item.intro" :type="item.type"></detail-card>
			</view>
		</mescroll-uni>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	import {
		getOverList
	} from '@/api/homepage'
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js"
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				hotList: [],
				upOption: {
					textNoMore: '没有更多了',
					noMoreSize: 4
				},
				page: 1,
				pageSize: 20
			}
		},
		computed: {
			...mapState({
				iStatusBarHeight: state => state.global.iStatusBarHeight,
			}),
			top() {
				return this.iStatusBarHeight + 88 + 30
			}
		},
		methods: {
			init() {
				getOverList({
						page: this.page,
						pageSize: this.pageSize
					})
					.then((res) => {
						this.hotList = [...this.hotList, ...res.data.list]
						this.page++
						this.mescroll.endSuccess(res.data.list.length)
					})
					.catch((e) => {
						console.log(e)
					})
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll
			},
			downCallback() {
				this.mescroll.resetUpScroll()
			},
			// 上拉
			upCallback() {
				this.init()
			},
		}
	}
</script>

<style>
</style>
